<template>
  <div class="list-container">
    <div class="back-btn">
      <ArrowLeftOutlined @click="back" class="back-icon" />
    </div>
    <div class="singer-info">
      <div class="item-info">
        <a-avatar
          shape="square"
          :size="64"
          :src="getSingerPic(compState?.singer.pic)"
          class="singer-avator"
        >
          <template #icon v-if="!compState?.singer.pic">
            <UserOutlined />
          </template>
        </a-avatar>
      </div>
      <div class="info-box">
        <div>{{ compState?.singer.name }}</div>
        <div>
          {{
            compState?.singer.sex === 1
              ? "男"
              : compState?.singer.sex === 0
              ? "女"
              : ""
          }}
        </div>
        <div>{{ compState?.singer.birth }}</div>
        <div>{{ compState?.singer.introduction }}</div>
      </div>
    </div>
    <div class="songs-container">
      <songsShow
        :songs="state.songs"
        :name="compState?.singer.name"
      ></songsShow>
    </div>
  </div>
</template>

<script setup lang="ts">
import {
  reactive,
  toRefs,
  ref,
  computed,
  onMounted,
  defineAsyncComponent,
  shallowRef,
  useAttrs,
} from "vue";
import type { Ref } from "vue";
import { getSongsBySinger } from "@/api/api.ts";
import type { singerType, singerStateType } from "@/types/pageTypes/singers";
const compState: Ref<singerStateType | null | undefined> = defineModel();
import useStore from "@/pinia/index.ts";
const { user } = useStore();
const state = reactive({
  songs: [],
});
const getSingerPic = (pic: string | undefined): string => {
  return import.meta.env.VITE_APP_BASE_SERVER + pic;
};
const getSongs = (): void => {
  let userId = user.userInfo.id ? user.userInfo.id : 99999999;
  let singerId: number | undefined = compState.value?.singer.id;
  if (singerId && userId) {
    getSongsBySinger(userId, singerId).then((result) => {
      if (result.data?.length) {
        state.songs = result.data;
      }
    });
  }
};

const back = () => {
  if (compState.value) compState.value.page = "list";
};

onMounted(() => {
  getSongs();
});
</script>

<style scoped lang="less">
.list-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  .back-btn {
    display: flex;
    flex-direction: row-reverse;
    padding: 10px 10px 0;
    .back-icon {
      font-size: 20px;
    }
  }
  .singer-info {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    .info-box {
      margin-left: 20px;
      flex: 1;
      display: flex;
      flex-direction: column;
      text-align: left;
    }
  }
  .songs-container {
    flex: 1;
    overflow: hidden;
  }
}
</style>
